import now from "../apis/now.js"

const moneyData = {
	state: {
		money: []
	},
	getters: {
		setMoney(state) {
			return state.money.filter((item) => {
				return item.date === now()
			})
		}
	},
	mutations: {
		getMoney(state) {
			state.money = JSON.parse(uni.getStorageSync('money') || '[]')
		},
		addMoney(state, payload) {
			if (payload.number === undefined) {
				return
			} else {
				this.commit("getMoney")
				state.money.push({
					date: now(),
					theme: payload.theme,
					number: payload.number,
					note: payload.note
				})
				console.log(state.money)
				uni.setStorageSync('money', JSON.stringify(state.money))
			}
		},
		setMoney() {},
		// delMoney() {},

	}
}

export default moneyData;
